package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.twins.log.LogTwinsDrawKungFu;
import com.yanqu.road.entity.activity.twins.log.LogTwinsKungFuCombUnlock;
import com.yanqu.road.entity.activity.twins.log.LogTwinsKungFuUpgrade;
import com.yanqu.road.entity.activity.twins.log.LogTwinsPveBattle;

import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogTwinsDaoImpl extends TempDao {

    public boolean addLogTwinsKungFuDrawList(List<LogTwinsDrawKungFu> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_twins_draw_kungfu" +
                " (activityId,userId,cost,kungfuId,value,integral,time) " +
                " VALUES(?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogTwinsDrawKungFu data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getCost()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getKungfuId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getValue()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getIntegral()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getTime())));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }


    public boolean addLogTwinsKungFuUpgradeList(List<LogTwinsKungFuUpgrade> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_twins_kungfu_upgrade" +
                " (activityId,userId,kungfuId,olevel,nlevel,oParam,nParam,time) " +
                " VALUES(?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogTwinsKungFuUpgrade data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getKungfuId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOlevel()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getNlevel()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getoParam()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getnParam()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getTime())));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogTwinsKungFuCombUplockList(List<LogTwinsKungFuCombUnlock> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_twins_comb_unlock" +
                " (activityId,userId,combId,time) " +
                " VALUES(?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogTwinsKungFuCombUnlock data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCombId()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getTime())));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogTwinsPveBattleList(List<LogTwinsPveBattle> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_twins_battle" +
                " (activityId,userId,missionId,bossId,refreshTimes,kungfuValue,attackValue,bossKungfuValue,bossAttackValue,isPass,randomReward,passReward,failReward,time) " +
                " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogTwinsPveBattle data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getMissionId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getBossId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getRefreshTimes()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getKungfuValue()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getAttackValue()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getBossKungfuValue()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getBossAttackValue()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getIsPass()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getRandomReward()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getPassReward()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getFailReward()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getTime())));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

}
